package com.iwechat.adapter.mina.entity;

import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;

/**
 * 协议单元
 *
 *
 */
public interface PDU {

    public static final int HEAD_LEN                     = 20;

    public static final int COMMAND_CONNECT              = 0x01;
    public static final int COMMAND_CONNECT_RESP         = -0x01;

    public static final int COMMAND_EXIT                 = 0x02;
    public static final int COMMAND_EXIT_RESP            = -0x02;

    public static final int COMMAND_SUBMIT               = 0x03;
    public static final int COMMAND_SUBMIT_RESP          = -0x03;

    public static final int COMMAND_ACTIVE               = 0x04;
    public static final int COMMAND_ACTIVE_RESP          = -0x04;

    public static final int COMMAND_DELIVEY              = 0x05;
    public static final int COMMAND_DELIVEY_RESP         = -0x05;

    public static final int ERRORCODE_SUCCESS            = 0;
    public static final int ERRORCODE_PKG_ERROR          = 100;

    public static final int ERRORCODE_CONN_VERIFY_FAIL   = 200;
    public static final int ERRORCODE_CONN_TOO_MANY      = 201;

    public static final int ERRORCODE_SUB_TOO_FAST       = 301;
    public static final int ERRORCODE_SUB_NO_LOGIN       = 302;

    public static final int ERRORCODE_DATA_PREPARE_ERROR = 401;

    static final Logger     logger                       = LogManager.getLogger();

    /**
     * 获取对象的iobuffer
     *
     *
     * @param charset
     * @return
     * @throws CharacterCodingException
     */
    IoBuffer toIoBuffer(Charset charset) throws Exception;

}
